package com.blt.car.base;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blt.car.R;
import com.blt.car.widget.CommonTitleBar;


/**
 * Description : 统一实现title bar
 *
 * Creation    : 2016/12/15
 * Author      : xugaopan
 */
public abstract   class BaseTitleBarActivity extends BaseActivity {

    protected CommonTitleBar mTitleBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }



    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(R.layout.activity_base_title_bar);
        ViewGroup contentView = (ViewGroup) findViewById(R.id.base_content);
        View view = LayoutInflater.from(this).inflate(layoutResID,contentView,false);
        contentView.addView(view);
        initTitleBar();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(R.layout.activity_base_title_bar);
        ViewGroup contentView = (ViewGroup) findViewById(R.id.base_content);
        contentView.addView(view);
        initTitleBar();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(R.layout.activity_base_title_bar);
        ViewGroup contentView = (ViewGroup) findViewById(R.id.base_content);
        contentView.addView(view,params);
        initTitleBar();
    }

    private void initTitleBar(){
        mTitleBar = (CommonTitleBar) findViewById(R.id.title_bar);
        mTitleBar.setLeftImageClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    public void setTitle(int resId){
        mTitleBar.setTitle(resId);
    }

    protected void setTitle(String title){
        mTitleBar.setTitle(title);
    }
}
